<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui">

<h:head>
	<link rel="stylesheet"
		href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
	</link>

	<title>Activity planner</title>
</h:head>

<h:body>

	<div class="navbar navbar-inverse">
		<div class="navbar-inner">
			<div class="container-fluid">
				<a class="btn btn-navbar" data-toggle="collapse"
					data-target=".nav-collapse"> <span class="icon-bar"></span> <span
					class="icon-bar"></span> <span class="icon-bar"></span>
				</a> <a class="brand" href="faces/activities.xhtml" name="top">Activity
					planner</a>
				<div class="nav-collapse collapse">
					<ul class="nav">

						<li><a href="login.xhtml"> Login </a></li>
						<li class="divider-vertical"></li>

						<h:panelGroup rendered="#{userBean.currentUser.role=='admin'}">
							<li><a href="userlist.xhtml"> User list </a></li>
							<li class="divider-vertical"></li>
						</h:panelGroup>

						<li><a href="edituser.xhtml"> Your profile </a></li>
						<li class="divider-vertical"></li>

					</ul>
					<div class="btn-group pull-right">
						<a class="btn dropdown-toggle" data-toggle="dropdown"
							href="login.xhtml"> <i class="icon-user"></i> Hello,
							#{userBean.currentUser.name}! <span class="caret"></span>
						</a>
						<ul class="dropdown-menu">
							<li><a href="#"><i class="icon-wrench"></i> Settings</a></li>
							<li class="divider"></li>
							<li><a href="#"><i class="icon-share"></i> User list</a></li>
						</ul>
					</div>
				</div>
				<!--/.nav-collapse -->
			</div>
			<!--/.container-fluid -->
		</div>
		<!--/.navbar-inner -->
	</div>
	<!--/.navbar -->

	<h:panelGroup id="dynaFormGroup">
		<p:messages id="messages" showSummary="true" />

	</h:panelGroup>

	<h:form class="text-info">
		<table>
			<tr>
				<td><label path="name"> Activity </label></td>
				<td><h:inputText id="name" value="#{activityBean.name}"
						size="20" required="true" label="Name">
					</h:inputText></td>
			</tr>
			<tr>
				<td><label path="startDate"> Start date </label></td>
				<td><p:calendar value="#{activityBean.startDate}"
						id="startDate" binding="#{startDate}" showOn="button"
						converterMessage="Invalid Date" pattern="dd.MM.yyyy"
						navigator="true" required="true" yearRange="-100"
						title="Start date">
					</p:calendar></td>
			</tr>
			<tr>
				<td><label path="dueDate"> Due date </label></td>
				<td><p:calendar value="#{activityBean.dueDate}" id="dueDate"
						binding="#{dueDate}" showOn="button"
						converterMessage="Invalid Date" pattern="dd.MM.yyyy"
						navigator="true" required="true" yearRange="-100" title="Due date">

					</p:calendar></td>
			</tr>

		</table>

		<h:commandButton value="Add activity" class="btn-info btn"
			action="#{activityBean.addAction()}" />

	</h:form>

	<h:form class="text-info" method="post">
		<h2>All activities for #{userBean.currentUser.name}</h2>
		<h:dataTable border="1"
			value="#{activityBean.getListAllActivities(activityBean.userBean.currentUser.id)}"
			var="o">

			<h:column>
				<f:facet name="header">Activity</f:facet>
				<h:inputText value="#{o.name}" size="20" rendered="#{o.editable}" />
				<h:outputText value="#{o.name}" rendered="#{not o.editable}" />
			</h:column>

			<h:column>
				<f:facet name="header">Start date</f:facet>

				<h:inputText value="#{o.startDate}" size="10" required="true"
					rendered="#{o.editable}">
					<f:convertDateTime pattern="dd.MM.yyyy" />
				</h:inputText>

				<h:outputText value="#{o.startDate}" rendered="#{not o.editable}">
					<f:convertDateTime type="date" pattern="dd.MM.yyyy" />
				</h:outputText>

			</h:column>

			<h:column>
				<f:facet name="header">Due date</f:facet>
				<h:inputText value="#{o.dueDate}" size="10" required="true"
					rendered="#{o.editable}">
					<f:convertDateTime pattern="dd.MM.yyyy" />
				</h:inputText>

				<h:outputText value="#{o.dueDate}" rendered="#{not o.editable}">
					<f:convertDateTime type="date" pattern="dd.MM.yyyy" />
				</h:outputText>
			</h:column>

			<h:column>
				<f:facet name="header">Done</f:facet>
				<h:outputText value="#{o.done}" />

			</h:column>

			<h:column>
				<h:commandLink value="Edit" action="#{activityBean.editAction(o)}"
					rendered="#{not o.editable}" />
			</h:column>

			<h:column>
				<h:commandLink value="Delete"
					action="#{activityBean.deleteAction(o.id)}"
					rendered="#{not o.editable}" />
			</h:column>

			<h:column>
				<h:commandLink value="Done!"
					action="#{activityBean.markActivityDone(o.id)}" />
			</h:column>

			<h:column>
				<h:commandLink value="Undone"
					action="#{activityBean.markActivityUndone(o.id)}" />
			</h:column>

		</h:dataTable>

	</h:form>

</h:body>

</html>